/**   
* @Title: CollectBillServiceImpl.java 
* @Package cn.kxm.service.impl 
* @Description: TODO(用一句话描述该文件做什么) 
* @author 初雨泽
* @date 2018年10月16日 下午3:27:00   
*/
package cn.kxm.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.kxm.dao.InstroageBillDao;
import cn.kxm.dao.CollectBillDao;
import cn.kxm.dao.CollectBillDetailDao;
import cn.kxm.pojo.Company;
import cn.kxm.pojo.CollectBill;
import cn.kxm.pojo.CollectBillDetail;
import cn.kxm.service.CollectBillService;

/** 
* @ClassName: CollectBillServiceImpl 
* @Description: TODO(这里用一句话描述这个类的作用) 
* @author 初雨泽
* @date 2018年10月16日 下午3:27:00 
*  
*/
@Service
public class CollectBillServiceImpl implements CollectBillService{
	
	@Autowired
	CollectBillDao collectBillDao;
	
	@Autowired
	CollectBillDetailDao collectBillDetailDao;
	
	@Autowired
	InstroageBillDao instroageBillDao;

	/* (non-Javadoc)
	 * @see cn.kxm.service.CollectBillService#searchCollectBill(java.lang.Integer, java.lang.Integer, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
	 */
	@Override
	public List<CollectBill> searchCollectBill(Integer page, Integer rows, String findcode, String findstartDate,
			String findendDate, String findsupplierName) {
		return collectBillDao.searchCollectBill(((page-1)*rows), rows, findcode, findstartDate, findendDate, findsupplierName);
	}
	/* (non-Javadoc)
	 * @see cn.kxm.service.CollectBillService#countSearchCollectBill(java.lang.Integer, java.lang.Integer, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
	 */
	@Override
	public int countSearchCollectBill (String findcode, String findstartDate, String findendDate,
			String findsupplierName) {
		return collectBillDao.countSearchCollectBill(findcode, findstartDate, findendDate, findsupplierName);
	}
	/* (non-Javadoc)
	 * @see cn.kxm.service.CollectBillService#deleteCollectBillByCode(java.lang.String)
	 */
	@Override
	public void deleteCollectBillByCode(String code) {
		collectBillDao.deleteCollectBillByCode(code);
	}
	/* (non-Javadoc)
	 * @see cn.kxm.service.CollectBillService#searchCompany(java.lang.String, java.lang.String, java.lang.Integer, java.lang.Integer, java.lang.Integer)
	 */
	@Override
	public List<Company> searchCompany(String code, String name, Integer type, Integer page, Integer rows) {
		return collectBillDao.searchCompany(code, name, type, ((page-1)*rows), rows);
	}
	/* (non-Javadoc)
	 * @see cn.kxm.service.CollectBillService#countSearchCompany(java.lang.String, java.lang.String, java.lang.Integer)
	 */
	@Override
	public int countSearchCompany(String code, String name, Integer type) {
		return collectBillDao.countSearchCompany(code, name, type);
	}
	/* (non-Javadoc)
	 * @see cn.kxm.service.CollectBillService#findCollectBill(java.lang.String)
	 */
	@Override
	public CollectBill findCollectBill(String code) {
		return collectBillDao.findCollectBill(code);
	}
	/* (non-Javadoc)
	 * @see cn.kxm.service.CollectBillService#updateCollectBillType(java.lang.String, java.lang.Integer)
	 */
	@Override
	public void updateCollectBillType(String code, Integer type) {
		collectBillDao.updateCollectBillType(code, type);
	}
	/* (non-Javadoc)
	 * @see cn.kxm.service.CollectBillService#updateCollectBill(java.lang.String, java.lang.Integer, java.lang.String, java.lang.String)
	 */
	@Override
	public void updateCollectBill(String collectData, Integer collectType, String memo, String code,Float collectTotalMoney) {
		System.out.println("collectTotal_f:"+collectTotalMoney);
		collectBillDao.updateCollectBill(collectData, collectType, memo, code, collectTotalMoney);
	}
	/* (non-Javadoc)
	 * @see cn.kxm.service.CollectBillService#addCollectBill(cn.kxm.pojo.CollectBill)
	 */
	@Override
	public void addCollectBill(CollectBill collectbill) {
		collectBillDao.addCollectBill(collectbill);
	}
	/* (non-Javadoc)
	 * @see cn.kxm.service.CollectBillService#deleteCollectBillUnchecked(java.lang.String)
	 */
	@Override
	public void deleteCollectBillUnchecked(String collectCode) {
		collectBillDetailDao.deleteDetailListByCollectBill(collectCode);
		collectBillDao.deleteCollectBill(collectCode);
	}
	/* (non-Javadoc)
	 * @see cn.kxm.service.CollectBillService#deleteCollectBillChecked(java.lang.String)
	 */
	@Override
	public void deleteCollectBillChecked(String collectCode) {
		List<CollectBillDetail> collectBillDetailList= collectBillDetailDao.findCollectBillDetail(collectCode);
		for (CollectBillDetail a:collectBillDetailList) {
			instroageBillDao.updateInstroageBillType(a.getBillCode(), 1);
		}
		collectBillDetailDao.deleteDetailListByCollectBill(collectCode);
		collectBillDao.deleteCollectBill(collectCode);
	}
	/* (non-Javadoc)
	 * @see cn.kxm.service.CollectBillService#findAllCollectBill()
	 */
	@Override
	public List<CollectBill> findAllCollectBill() {
		return collectBillDao.findAllCollectBill();
	}
}
